<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>vue3-escook</title>
  <link rel="stylesheet" href="./lib/style.css">
  <script type="importmap">
    {
      "imports" : {
        "vue": "./lib/vue-3.4.29.js"
      }
    }
  </script>
  <script type="module">
    import { createApp, ref, watch, watchEffect, watchPostEffect } from 'vue'

    const app = createApp({
      setup() {
        const count = ref(0)

        // 默认情况下，副作用函数在数据变化后、DOM 更新前被执行
        // 因此，在副作用函数中获取不到最新的 DOM 元素
        // watch(count, () => {
        //   const h1DOM = document.querySelector('h1')
        //   console.log(h1DOM?.textContent)
        // }, {
        //   // 把副作用函数的执行时机，推迟到 DOM 更新完毕
        //   flush: 'post'
        // })

        // watchEffect(() => {
        //   console.log(count.value)
        //   const h1DOM = document.querySelector('h1')
        //   console.log(h1DOM?.textContent)
        // }, {
        //   // 把副作用函数的执行时机，推迟到 DOM 更新完毕
        //   flush: 'post'
        // })

        watchPostEffect(() => {
          console.log(count.value)
          const h1DOM = document.querySelector('h1')
          console.log(h1DOM?.textContent)
        })

        return {
          count
        }
      }
    })

    app.mount('#app')
  </script>
</head>

<body>
  <div id="app">
    <h1>count 的值是：{{ count }}</h1>
    <button @click="count++">+1</button>
  </div>
</body>

</html>